home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
szadb1_4.zoo
/
src
/
adb.c
next >
Wrap
C/C++ Source or Header
|
1991-07-07
|
23KB
|
1,171 lines
/* Copyright (c) 1990 by Sozobon, Limited. Authors: Johann Ruegg, Don Dugger
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to redistribute it freely, with the
* following restrictions:
* 1) No charge may be made other than reasonable charges for reproduction.
* 2) Modified versions must be clearly marked as such.
* 3) The authors are not responsible for any harmful consequences
* of using this software, even if they result from defects in it.
*
* adb.c
*/
/*
* Modified to allow adb execute strings of commands stored in memory.
* Added buffered transcript output to named files.
* Changes in accepted request syntax.
* More elaborate command line.
*
* Michal Jaegermann, May 1990
*
* Symbol table display is now paging - it was just too fast for TT.
* ('q', 'Q' or CNTLC will get you out - any other key continues)
* Michal Jaegermann, July 1991
*
*/
#include <setjmp.h>
#include <fcntl.h>
#include "adb.h"
#define IN_ADB
#include "lang.h"
#define CNTLC 3
#define CNTLS 0x13
#define CNTLW 0x17
#define CHUNK 0x4000L;
long _BLKSIZ = CHUNK; /* granularity of memory allocation */
struct file binary;
int swidth; /* max width of symbol name - unknown so far */
long dot;
int dotoff;
long olddot;
#define DOT (dot+dotoff)
int dotset;
long maxoff = 0x400;
int ibase = 10;
int lastc = 0;
char sign = 0;
long bcount;
int click = 0; /* flag for cmdcol */
extern int write (), bf_write ();
char trname[LINESZ + 2]; /* transcript file name */
int trid = NO_TRANS;/* its descriptor */
w_buf *trbuf = (w_buf *) 0; /* pointer to its buffer */
int (*trout) () = write;
unsigned long regbuf[19];
struct regs regs[] = {
"pc", ®buf[16],
"sr", ®buf[17],
"xsp", ®buf[18],
"d0", ®buf[0],
"d1", ®buf[1],
"d2", ®buf[2],
"d3", ®buf[3],
"d4", ®buf[4],
"d5", ®buf[5],
"d6", ®buf[6],
"d7", ®buf[7],
"a0", ®buf[8],
"a1", ®buf[9],
"a2", ®buf[10],
"a3", ®buf[11],
"a4", ®buf[12],
"a5", ®buf[13],
"a6", ®buf[14],
"sp", ®buf[15],
"", 0,
};
#define NREGS 19
jmp_buf jmpb, trp_buf;
static char cnbuf[LINESZ + 2];
#define CONSOLE &cnbuf[0]
int l_restart, w_restart, lb_cur, lb_fill;
char *lbuf = CONSOLE;
int getkchr (), getschr ();
static char *csource; /* location read by a function getschr() */
static int (*getachr) () = getkchr;
extern int print_regs;
extern struct window w;
char **bpt_cmds;
char **ftable;
_main ()
{
extern int _argc;
extern char **_argv;
main (_argc, _argv);
exit (0);
}
main (argc, argv)
int argc;
char *argv[];
{
char *cp, c;
extern long ossp;
int i, no_cmds, no_buf;
void adb (), copyargs (), kdefs (), free (), usage ();
char *malloc ();
winopen ();
*argv++; /* skip starting argument */
no_cmds = no_buf = 0;
while ('-' == **argv) {
(*argv)++; /* skip dash */
while ('\0' != (c = ~' ' & **argv)) {
(*argv)++; /* skip leading letter */
if ('N' == c) {
while ('\0' != (c = ~' ' & **argv)) {
if ('C' == c)
no_cmds = 1;
else if ('B' == c)
no_buf = 1;
else
usage ();
(*argv)++; /* to next character */
}
break; /* done with option */
}
else if ('K' == c) {
if ('\0' == **argv) {
if (0 == --argc) /* out of arguments? */
usage ();
*argv++;
}
kdefs (*argv); /* load definitions of fuction keys */
break;
}
else if ('O' == c) { /* tell which object format */
if ('\0' == **argv) {
if (0 == --argc) /* out of arguments? */
usage ();
*argv++;
}
if ('M' == (~' ' & **argv))
swidth = 16; /* this is MWC symbpl table */
else
swidth = 8; /* we'll take anything else for DRI */
break;
}
else
usage ();
} /* while ('\0' != (c = ~' ' & **argv)) */
if (0 == --argc)
usage ();
*argv++; /* to next argument */
} /* while ('-' == **argv) */
ibase = 16;
if (0 == no_cmds) {
i = 0;
if ((char **) 0 != (bpt_cmds =
(char **) malloc (MAXBPTS * sizeof(char *)))) {
while (i < MAXBPTS) {
if ((char *) 0 == (bpt_cmds[i] = malloc (LINESZ + 3)))
break;
i++;
}
}
if (i < MAXBPTS) {
prt ("not enough memory for breakpoint requests\n");
while (i > 0) {
--i;
free (bpt_cmds[i]);
}
if ((char **) 0 != bpt_cmds)
free (bpt_cmds);
}
}
if (0 == no_buf) { /* set write-to-file function to unbuffered
* write */
if ((w_buf *) 0 ==
(trbuf = (w_buf *) malloc (sizeof (w_buf)))) {
prt (M7); /* warning - transcript unbuffered */
}
else {
trbuf->buf_len = TRBUFSZ;
trbuf->buffered = 0;
trout = bf_write;
}
}
binary.symptr = 0;
/* binary.flags = 0; */
if (0 == --argc) {
usage ();
}
binary.name = *argv++;
if ((binary.fid = open (binary.name, 0)) < 0) {
/* prtf("%s:cannot open\n", binary.name); */
prtf (M1, binary.name);
seeerr ();
exit (2);
}
if (setobj () != 0) {
/* prtf("%s:bad format\n", binary.name); */
prtf (M2, binary.name);
seeerr ();
exit (3);
}
if (loadpcs () != 0) {
/* prtf("%s:bad pexec\n", binary.name); */
prtf (M3, binary.name);
seeerr ();
exit (4);
}
close (binary.fid);
copyargs (--argc, argv); /* if any left - copy for a process to debug */
relsym ();
vects ();
/* prt("Szadb version 1.2 (english)\n"); */
prt (M4);
if (setjmp (trp_buf)) {
seeerr ();
exit (0);
}
adb (1);
}
void
usage ()
{
/* prtf ("Usage: adb [-nb] [-nc] [-k kdefs] [-o(s|m)] binary [args]\n"); */
prtf (M_USE);
seeerr ();
exit (1);
}
exit (n)
{
void trclose ();
oldvects ();
winclose ();
trclose ();
_exit (n);
}
seeerr ()
{
/* prt("(hit any key)"); */
prt (M5);
gemdos (7);
}
#define MWC_START 0x2a6f0004
setobj ()
{
struct fheader hdr;
long guess;
int fid = binary.fid;
if ((read (fid, &hdr, sizeof (hdr)) != sizeof (hdr)) &&
(MAGIC != hdr.magic))
return -1;
/* an empty MWC symbol table may use 0x30 bytes for something (?) */
if ((hdr.ssize) && (0x30L != hdr.ssize)) {
if (sizeof(long) != read(fid, &guess, sizeof(long)))
return -1;
if (0 == swidth) { /* nobody told what is the format */
swidth = (MWC_START == guess ? 16 : 8);
}
lseek (fid, hdr.tsize + hdr.dsize - (long)(sizeof(long)), 1);
if (16 == swidth)
return mwsetsym (fid, hdr.ssize);
else {
if (extndsymb(fid, hdr.ssize))
swidth = 22;
return setsym (fid, hdr.ssize);
}
}
return 0;
}
void
adb (top)
int top;
{
int cmddol (), cmdcol (), cmdprt ();
int cmdwrt (), cmdsreg (), null ();
long getn (), getdot ();
long expr ();
int intr ();
register int c, lc;
register long count;
int (*f) ();
long (*g) ();
char fmt[LINESZ];
if (top) {
f = cmdprt;
g = getdot;
lc = '=';
fmt[0] = 'a';
fmt[1] = '\n';
fmt[2] = '\0';
setjmp (jmpb);
}
for (;;) {
dotoff = 0;
if (type (c = PEEKC) & (ALPHANUM | SPECX)) {
dot = expr ();
olddot = dot;
dotset = 1;
}
else
dotset = 0;
if (PEEKC == ',') {
nb (); /* consume pushed comma */
count = expr ();
}
else
count = 1L;
switch (c = nb ()) {
case '>':
f